package cn.edu.abtu.service.impl;

import cn.edu.abtu.dao.EduCourseDao;
import cn.edu.abtu.dao.EduTeacherDao;
import cn.edu.abtu.entity.EduCourse;
import cn.edu.abtu.entity.EduTeacher;
import cn.edu.abtu.service.IndexFrontService;
import cn.edu.abtu.vo.ResponseData;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

@Service
public class IndexFrontServiceImpl implements IndexFrontService {

    @Autowired
    private EduCourseDao eduCourseDao;

    @Autowired
    private EduTeacherDao eduTeacherDao;

    @Override
    public ResponseData index() {
        //查询八门热门课程
        QueryWrapper<EduCourse> courseQueryWrapper = new QueryWrapper<>();
        courseQueryWrapper.orderByDesc("id");
        courseQueryWrapper.last("limit 8");
        List<EduCourse> eduCourseList = eduCourseDao.selectList(courseQueryWrapper);
        //查询四个讲师
        QueryWrapper<EduTeacher> teacherQueryWrapper = new QueryWrapper<>();
        teacherQueryWrapper.orderByAsc("id");
        teacherQueryWrapper.last("limit 4");
        List<EduTeacher> eduTeacherList = eduTeacherDao.selectList(teacherQueryWrapper);
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("eduCourseList",eduCourseList);
        hashMap.put("eduTeacherList",eduTeacherList);
        return ResponseData.success("查询成功",hashMap);
    }
}
